package com.bigdata.team2.finalproject;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.annotation.PostConstruct;
import javax.sql.DataSource;

@Configuration
public class DatabaseConfig {
    private org.slf4j.Logger logger = LoggerFactory.getLogger(this.getClass());
    public void showMsg (String msg){
        logger.error(msg);
    }

    @Bean
    @Primary
    @ConfigurationProperties(prefix = "spring.datasource")
    @PostConstruct
    public DataSource DataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean
    public JdbcTemplate jdbcTemplate(@Qualifier("DataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

}
